<template>
  <div style="margin-top: 50px">
    <van-tabbar v-model="active" route>
      <van-tabbar-item icon="home-o" to="/">首页</van-tabbar-item>
      <van-tabbar-item icon="apps-o" to="/fenlei">分类</van-tabbar-item>
      <van-tabbar-item icon="underway-o" v-if="$store.state.user" to="/sigin">签到</van-tabbar-item>
      <van-tabbar-item icon="shopping-cart-o" to="/cart" :badge="$store.state.badge">购物车</van-tabbar-item>
      <van-tabbar-item icon="friends-o" to="/user">个人中心</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
export default {
  data() {
    return {
      active: 0,
      badge: 0
    };
  },
  methods: {
    get() {
      this.$post(this.url2 + "/cart/countCart", {
        userId: this.$store.state.user.id
      }).then(res => {
        console.log(res);
        if (res.errorCode == '0') {
          this.badge = res.data
          this.$store.commit("setbage", res.data)
        }
      })
    }
  },
  created() {
    this.get()
  },
};
</script>

<style  scoped>
</style>